package cn.xiaopengstack.types.enums;

import cn.xiaopengstack.types.model.Response;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Optional;
import java.util.stream.Stream;

/**
 * @author jiangyangang
 */

@AllArgsConstructor
@NoArgsConstructor
@Getter
public enum ResponseCode {

    SUCCESS("0000", "成功"),
    UN_ERROR("0001", "未知失败"),
    ILLEGAL_PARAMETER("0002", "非法参数"),
    STRATEGY_RULE_WEIGHT_IS_NULL("ERR_BIZ_001", "业务异常，策略规则中 rule_weight 权重规则已适用但未配置"),
    STRATEGY_RULE_BLACK_IS_NULL("ERR_BIZ_002", "业务异常，策略规则中 rule_blacklist 未配置"),
    STRATEGY_RULE_RANGE_NULL("ERR_BIZ_003", "业务异常，抽奖规则未配置!"),
    UNKNOWN_ACTIVITY_ACTION("ERR_BIZ_004", "业务异常，未知的活动责任链规则%s"),
    ACTIVITY_CREATE_FAIL("ERR_BIZ_005", "业务异常，活动事件入账失败"),
    INDEX_DUP("ERR_BIZ_006", "业务异常，活动事件重入"),
    ACTIVITY_STOCK_SELL_OUT("ERR_BIZ_007", "业务异常，库存售罄"),
    ACTIVITY_STATUS_ERROR("ERR_BIZ_008", "业务异常，活动状态异常"),
    ACTIVITY_TIME_ERROR("ERR_BIZ_009", "业务异常，活动时间异常"),
    ACTIVITY_PARTAKE_ORDER_FAIL("ERR_BIZ_010", "业务异常，抽奖单库存逻辑执行失败"),
    ACCOUNT_QUOTA_ERROR("ERR_BIZ_011", "业务异常，账户总额度异常"),
    ACCOUNT_MONTH_QUOTA_ERROR("ERR_BIZ_012", "业务异常，账户月额度异常"),
    ACCOUNT_DAY_QUOTA_ERROR("ERR_BIZ_013", "业务异常，账户日额度异常"),
    AWARD_SAVE_ERROR("ERR_BIZ_014", "业务异常，奖品记录保存异常"),
    ACTIVITY_ARMORY_ERROR("ERR_BIZ_015", "业务异常，奖品信息装配异常"),
    DISTRIBUTE_AWARD_ERROR("ERR_BIZ_016", "发奖异常，没有原始发奖记录"),
    DISTRIBUTE_AWARD_NO_AWARD_ERROR("ERR_BIZ_017", "发奖异常，没有奖品记录"),
    DISTRIBUTE_AWARD_HANDLER_ERROR("ERR_BIZ_018", "发奖异常，没有发奖处理器"),
    CREDIT_SAVE_ORDER_ERROR("ERR_BIZ_019", "保存积分订单异常!"),
    ACTIVITY_RECHANGE_UPDATE_TRADE_ORDER_ERROR("ERR_BIZ_020", "更新活动返利交易类订单失败!"),
    DEGRADE_SWITCH("ERR_BIZ_021", "接口已降级!"),
    RATE_LIMITER("ERR_BIZ_022", "接口已限流，请稍后再试!"),
    HYSTRIX("ERR_BIZ_023", "接口已熔断，请稍后再试!"),
    ;

    private String code;
    private String info;

    public static Optional<ResponseCode> getResp(String code){
        return Stream.of(ResponseCode.values()).filter(e -> e.getCode().equals(code)).findFirst();
    }
}
